package org.moka.ioio.ioiopilot;

import org.moka.ioio.ioiopilot.gui.CommandPanel;
import org.moka.ioio.ioiopilot.gui.GraphSurface;

import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.ToggleButton;

public class IOIOPilotActivity extends Activity {


	private IOIOThread ioio_thread_;
	 
	private CommandPanel commandPanel_;
	private GraphSurface graphPanel_;
	private LinearLayout graphLegend_;
 
	/**
	 * Called when the activity is first created. Here we normally initialize
	 * our GUI.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		// title_ = (TextView) findViewById(R.id.title);
		// button_ = (ToggleButton) findViewById(R.id.button);
		commandPanel_ = (CommandPanel) findViewById(R.id.commandPanel);
		graphPanel_ = (GraphSurface) findViewById(R.id.graphPanel);
		graphLegend_ = (LinearLayout) findViewById(R.id.graphLegend);
		graphPanel_.addLegend(graphLegend_);
	}

	/**
	 * Called when the application is resumed (also when first started). Here is
	 * where we'll create our IOIO thread.
	 */
	@Override
	protected void onResume() {
		super.onResume();
		ioio_thread_ = new IOIOThread(getApplicationContext(), commandPanel_, graphPanel_); 
		ioio_thread_.start();
	}

	/**
	 * Called when the application is paused. We want to disconnect with the
	 * IOIO at this point, as the user is no longer interacting with our
	 * application.
	 */
	@Override
	protected void onPause() {
		super.onPause();
		ioio_thread_.abort();
		try {
			ioio_thread_.join();
		} catch (InterruptedException e) {
		}
	}
	
	
	
}